require(['loading'], function(loading) {
	//获取url中的id参数
	var params = getUrlParams();
	var detailId = params.id?params.id:"";
    //实例化
    var detail = new Vue({
        el: '#myPurchaseDetail',
        data: {
			headPic:'',
            bulkData: '',
            showLoading: false,
            apiUrl: wxUrl + '/v3.2/tbuyinginfo/detail.do',
			upordownUrl:wxUrl + '/v3.2/tbuyinginfo/upordown.do',
            item: {
                params:{
                    token: token,
                    userToken: userToken,
                    id:detailId
                }
            },
			itemUpordown: {
                params:{
                    token: token,
                    userToken: userToken,
                    id:detailId,
                    status: 1
                }
            },
			detailStatus:false
        },
        ready: function(){
            this.getIndexData()
        },
        methods: {
            getIndexData: function() {
                this.$http.get(this.apiUrl, this.item)
                .then(function(response) {
                    var result = JSON.parse(response.body);
                    console.log(result)
                    this.itemUpordown.params.status = result.data.result.status;
                    this.bulkData = result.data.result;
					if(this.bulkData.status == 1){
						this.detailStatus=true;
					}
					this.headPic=result.data.headPic
                });
            },
            upordown:function(action){
				this.itemUpordown.params.status = action;
                this.$http.post(this.upordownUrl,this.itemUpordown.params,{'emulateJSON':true})
                .then(function(response){
                    console.log(response);
					var result = JSON.parse(response.body);
					if(0==result.code){
						 promptBox("操作成功");
					}
				    if(action == 1){
						this.detailStatus=true;
				    }else{
						this.detailStatus=false;
					}
				});
            },
			toEditBuyOne:function(){
				location.href="editBuy.html?id="+detailId
			}
        },
    });
});
// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});